package nl.hro.mgdd.team4.raidersofhexagoniland.Scenes;

import org.andengine.entity.scene.Scene;

import Levels.*;
import Parts.Player;
import Utils.Vector2;

import nl.hro.mgdd.team4.raidersofhexagoniland.GameActivity;

public class SceneManager {

	public enum GameState { splashScreen, Menu, Playing }
	
	public static GameActivity _game;
	private static SceneManager _manager;
	private Scene _scene;
	private GameState _state;
	private static MainMenuScene _mainMenu;
	private static SplashScene _splash;
	
	private static LevelBaseScene _currentLevel;
	
	public static Player _player;
	public static Player _enemy;
	
	private static int _level;
	
	private SceneManager(){
		
	}
	
	public static void init(GameActivity game){
		SceneManager._game = game;
		_level = 0;
		_player = new Player(0, 0, 0);
		_enemy = new Player(0, 0, 0);
		_mainMenu = new MainMenuScene();
		_splash = new SplashScene();
		//_currentLevel = new W1Level1();
	}
	
	public static SceneManager getManager(){
		if(_game == null) throw new IllegalStateException("Screenmanager is not yet initialized");
		if(_manager == null) return _manager = new SceneManager();
		return _manager;
	}
	
	public Scene getCurrentScene(){
		return _scene;
	}
	
	public GameState getCurrentState(){
		return _state;
	}
	
	public void setSplashScene(){
		_scene = _splash;
		_state = GameState.splashScreen;
		_game.getEngine().setScene(_scene);
	}
	
	public void setMainMenuScene(){
		_scene = _mainMenu;
		_state = GameState.Menu;
		_game.getEngine().setScene(_scene);
	}
	
	public void setWorld1Level1(){
		_level = 1;
		_currentLevel = new W1Level1();
		_state = GameState.Playing;
		_scene = _currentLevel;
		_game.getEngine().setScene(_scene);
	}
	
	public void setWorld1Level2(){
		_level = 2;
		_currentLevel = new W1Level2();
		_state = GameState.Playing;
		_scene = _currentLevel;
		_game.getEngine().setScene(_scene);
	}
	
	public void setWorld1Level3(){
		_level = 3;
		_currentLevel = new W1Level3();
		_state = GameState.Playing;
		_scene = _currentLevel;
		_game.getEngine().setScene(_scene);
	}
	
	public void setWorld1Level4(){
		_level = 4;
		_currentLevel = new W1Level4();
		_state = GameState.Playing;
		_scene = _currentLevel;
		_game.getEngine().setScene(_scene);
	}
	
	public void setWorld1Level5(){
		_level = 5;
		_currentLevel = new W1Level5();
		_state = GameState.Playing;
		_scene = _currentLevel;
		_game.getEngine().setScene(_scene);
	}
	
	public void setNextLevel(){
		switch(_level){
		case 1:
			setWorld1Level2();
			break;
		case 2:
			setWorld1Level3();
			break;
		case 3:
			setWorld1Level4();
			break;
		case 4:
			setWorld1Level5();
			break;
		case 5:
			/* TODO handle victory*/
			break;
		}
	}
	
	public LevelBaseScene getCurrentLevel(){
		return _currentLevel;
	}
	
	public int getLevelNumber(){
		return _level;
	}
	
	public Vector2 getLevelSize(){
		return new Vector2(_currentLevel.getMapWidth(), _currentLevel.getMapHeight());
	}
	
	public static void reset(){
		_level = 1;
		_player = new Player(0, 0, 0);
		_enemy = new Player(0, 0, 0);
		_mainMenu = new MainMenuScene();
		_splash = new SplashScene();
		_currentLevel = new W1Level1();
	}
}
